home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / inet.cls < prev    next >
Encoding:
Visual Basic class definition  |  2004-05-21  |  9.2 KB  |  264 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "Inet"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. '/******************************************************************/
  15. '/*                                                                */
  16. '/*                      TurboCAD for Windows                      */
  17. '/*                   Copyright (c) 1993 - 2001                    */
  18. '/*             International Microcomputer Software, Inc.         */
  19. '/*                            (IMSI)                              */
  20. '/*                      All rights reserved.                      */
  21. '/*                                                                */
  22. '/******************************************************************/
  23. ' it is an example of simply tool that run I browser with predefined URL
  24. ' In order to use it select a graphic with URL property defined and then run Hyperlink tool
  25.  
  26. Option Explicit
  27.  
  28. 'Number of tools in this dll
  29. Const NUM_TOOLS = 1
  30. 'Toggle this to test loading buttons from .Bmp/.Res
  31. Const boolLoadFromBmp As Boolean = False
  32. Const boolDebug As Boolean = False
  33.  
  34. 'Return a description string for this package of tools
  35. Public Property Get Description() As String
  36.     Description = "Internet connection tool"
  37. End Property
  38.  
  39. 'Called to perform tool function
  40. Public Function Run(ByVal Tool As Object) As Boolean
  41.     Dim objApp As Object
  42.     Dim objSel As Object
  43.     Dim objGraphic As Object
  44.     Dim strURL As String
  45.     On Error Resume Next
  46.  
  47.     'Look for first URL property in the selection
  48.     Set objApp = Tool.Application
  49.     Set objSel = objApp.Selection
  50.     For Each objGraphic In objSel
  51. ' look for first graphic with URL defined
  52.         strURL = ""
  53.         strURL = objGraphic.Properties("URL")
  54.         If strURL <> "" Then
  55.             StartBrowser strURL
  56.             Run = True
  57.             Exit Function
  58.         End If
  59.     Next objGraphic
  60.  
  61.     'No selection or no URLs: just start browser at a convenient home page
  62.     ' no one graphic from selected have property URL filled so start the browser with default url
  63.     StartBrowser "http://www.imsisoft.com/"
  64.     Run = True
  65. End Function
  66.  
  67. 'Fill arrays with information about tools in the package
  68. 'Return the number of tools in the package
  69. Public Function GetToolInfo(CommandNames As Variant, MenuCaptions As Variant, StatusPrompts As Variant, _
  70.     ToolTips As Variant, Enabled As Variant, WantsUpdates As Variant) As Long
  71.     ReDim CommandNames(NUM_TOOLS)
  72.     ReDim MenuCaptions(NUM_TOOLS, 2)
  73.     ReDim StatusPrompts(NUM_TOOLS)
  74.     ReDim ToolTips(NUM_TOOLS)
  75.     ReDim Enabled(NUM_TOOLS)
  76.     ReDim WantsUpdates(NUM_TOOLS)
  77. '    CommandNames(0) = "SDK|Hyperlink" ' Menu + Command Name
  78.     CommandNames(0) = "&AddOns|S&DK Samples|&Tools|Hyperlink" + "#CMD_SDKHYPERLINK" ' Menu + Command Name
  79.     MenuCaptions(0, 0) = "&Hyperlink"
  80.     MenuCaptions(0, 1) = "SDK Samples" ' toolbar name
  81.     StatusPrompts(0) = "Launch a browser on the World Wide Web"
  82.     ToolTips(0) = "Hyperlink"
  83.     Enabled(0) = True
  84.     WantsUpdates(0) = False
  85.     GetToolInfo = NUM_TOOLS
  86. End Function
  87.  
  88.  
  89. 'Copy a windows bitmap of the requested size to the clipboard
  90. 'Bitmaps returned should contain NUM_TOOLS images
  91. 'Size of entire bitmap:
  92. 'Normal:  (NUM_TOOLS*16) wide x 15 high
  93. 'Large:   (NUM_TOOLS*24) wide x 23 high
  94. 'Mono bitmap should be 1-bit (black or white)
  95. Public Function CopyBitmap(ByVal LargeImage As Boolean, ByVal MonoImage As Boolean) As Boolean
  96.     On Error GoTo BitmapError
  97.  
  98.     Dim TheImage As New StdPicture
  99.     If GetButtonPicture(LargeImage, MonoImage, TheImage) Then
  100.         'Put the image on the Windows clipboard
  101.         Clipboard.SetData TheImage, vbCFDIB
  102.         CopyBitmap = True
  103.         Exit Function
  104.     End If
  105.  
  106. BitmapError:
  107.     CopyBitmap = False
  108. End Function
  109.  
  110. 'Return a Picture object for the requested size
  111. 'Apparently, returning references to StdPicture objects doesn't work for .EXE servers
  112. 'Bitmaps returned should contain NUM_TOOLS images
  113. 'Size of entire image:
  114. 'Normal:  (NUM_TOOLS*16) wide x 15 high
  115. 'Large:   (NUM_TOOLS*24) wide x 23 high
  116. 'Mono image should be 1-bit (black or white)
  117. Public Function GetPicture(ByVal LargeImage As Boolean, ByVal MonoImage As Boolean) As Object
  118.     On Error GoTo PictureError
  119.  
  120.     Dim TheImage As New StdPicture
  121.     If GetButtonPicture(LargeImage, MonoImage, TheImage) Then
  122.         Set GetPicture = TheImage
  123.         Exit Function
  124.     End If
  125.  
  126. PictureError:
  127.     Set GetPicture = Nothing
  128. End Function
  129.  
  130. 'Returns true if tool is correctly initialized
  131. Public Function Initialize(ByVal Tool As Object) As Boolean
  132.     Initialize = True
  133. End Function
  134.  
  135. 'Returns true if tool is correctly initialized
  136. Public Function UpdateToolStatus(ByVal Tool As Object, Enabled As Boolean, Checked As Boolean) As Boolean
  137.     Enabled = True 'Could do a test here to determine whether to disable the button/menu item
  138.     Checked = False  'Could do a test here to determine whether to check the button/menu item
  139.     UpdateToolStatus = True
  140. End Function
  141.  
  142. 'Implementation specific stuff
  143. 'Private function to return the bitmap from .Res file or .Bmp file
  144. Private Function GetButtonPicture(ByVal LargeImage As Boolean, ByVal MonoImage As Boolean, TheImage As StdPicture) As Boolean
  145.     On Error GoTo LoadError
  146.  
  147.     'There are two ways to load images:  from .Bmp file(s) or from .RES resource.
  148.     'In this demo, we control the loading by a private variable.
  149.     
  150.     'Note that if you are loading from .Bmp, or if you are running this tool as a
  151.     '.VBP for debugging, you must place the .Res or .Bmp files in the Draggers subdirectory
  152.     'of the directory in which TCW80.EXE (or IMSIGX90.dll) is located.
  153.  
  154.     If boolLoadFromBmp Then
  155.         'Load from .Bmp file
  156.         Dim strFileName As String 'File name of .Bmp file to load
  157.  
  158.         If LargeImage Then
  159.             strFileName = App.Path & "\button24.bmp"
  160.         Else
  161.             strFileName = App.Path & "\button16.bmp"
  162.         End If
  163.         Set TheImage = LoadPicture(strFileName)
  164.     Else
  165.         'Load from .Res file
  166.         Dim idBitmap%  'BITMAP resource id in .Res file
  167.  
  168.         If LargeImage Then
  169.             idBitmap% = 102
  170.         Else
  171.             idBitmap% = 101
  172.         End If
  173.         Set TheImage = LoadResPicture(idBitmap%, vbResBitmap)
  174.     End If
  175.  
  176.     'Return the image
  177.     GetButtonPicture = True
  178.     Exit Function
  179.  
  180. LoadError:
  181.     If boolDebug Then
  182.         MsgBox "Error loading bitmap: " & Err.Description
  183.     End If
  184.     GetButtonPicture = False
  185. End Function
  186.  
  187. 'We get the name of the installed internet browser from the Windows registry
  188. Private Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As String, vValue As Variant) As Long
  189.     Dim cch As Long
  190.     Dim lrc As Long
  191.     Dim lType As Long
  192.     Dim lValue As Long
  193.     Dim sValue As String
  194.  
  195.     On Error GoTo QueryValueExError
  196.  
  197.     ' Determine the size and type of data to be read
  198.     lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
  199.     If lrc <> ERROR_NONE Then Error 5
  200.  
  201.     Select Case lType
  202.         ' For strings
  203.         Case REG_SZ:
  204.             sValue = String(cch, 0)
  205.  
  206.             lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch)
  207.             If lrc = ERROR_NONE Then
  208.                 If cch > 0 Then
  209.                     cch = cch - 1
  210.                 End If
  211.                 vValue = Left$(sValue, cch)
  212.             Else
  213.                 vValue = Empty
  214.             End If
  215.         ' For DWORDS
  216.         Case REG_DWORD:
  217.             lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, lValue, cch)
  218.             If lrc = ERROR_NONE Then vValue = lValue
  219.         Case Else
  220.             'all other data types not supported
  221.             lrc = -1
  222.     End Select
  223.  
  224. QueryValueExExit:
  225.     QueryValueEx = lrc
  226.     Exit Function
  227.  
  228. QueryValueExError:
  229.     Resume QueryValueExExit
  230.  
  231. End Function
  232.  
  233. 'Get a string value from the registry
  234. Private Function QueryValueString(ByVal lRootKey As Long, ByVal sKeyName As String, ByVal sValueName As String) As String
  235.     Dim lRetVal As Long         'result of the API functions
  236.     Dim hKey As Long         'handle of opened key
  237.     Dim vValue As Variant      'setting of queried value
  238.  
  239.     lRetVal = RegOpenKeyEx(lRootKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
  240.     lRetVal = QueryValueEx(hKey, sValueName, vValue)
  241.     QueryValueString = vValue
  242.     RegCloseKey (hKey)
  243. End Function
  244.  
  245. 'Private function to startup the registered internet browser at a specified URL
  246. Private Function StartBrowser(strURL As String)
  247.     Dim HRes As Long
  248.     Dim TheKey As Long
  249.     Dim strExec As String
  250.     
  251.     'Get the browser command from the registry
  252.     strExec = QueryValueString(HKEY_LOCAL_MACHINE, "SOFTWARE\Classes\HTTP\shell\open\command", "")
  253.     If strExec <> "" Then
  254.         If strURL <> "" Then
  255.         
  256.             'Embed the URL in quotes and build a command line
  257.             strExec = strExec & " " & Chr$(34) & strURL & Chr$(34)
  258.         End If
  259.         
  260.         'Invoke the browser
  261.         WinExec strExec, SW_SHOW
  262.     End If
  263. End Function
  264.